package com.ericd.util.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class InputStreamFile {
	
	private InputStream inputStream = null;

	public InputStreamFile(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	
	public void write(File file) throws IOException {
		File dir = file.getParentFile(); 
		if(dir!=null && !dir.exists()) {
			dir.mkdirs();
		}
		FileOutputStream fileOut = new FileOutputStream(file);
		int avail = 0;
		while((avail=inputStream.available()) > 0) {
			byte b[] = new byte[avail];
			inputStream.read(b);
			fileOut.write(b);
		}
		fileOut.flush();
		fileOut.close();
	}
}
